package com.lin.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lin.po.AddressPO;
import com.lin.po.UserPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


@Mapper
public interface UserPOMapper extends BaseMapper<UserPO> {
    @Update("update user set balance = balance - #{balance} ${ew.customSqlSegment}")
    void minusBalanceByIds(@Param(Constants.WRAPPER) LambdaQueryWrapper<UserPO> wrapper,
                              @Param("balance")Integer balance);

    @Update("update user set balance = balance + #{balance} ${ew.customSqlSegment}")
    void addBalanceByIds(@Param(Constants.WRAPPER) LambdaQueryWrapper<UserPO> wrapper,
                            @Param("balance")Integer balance);

    @Update("update user set balance = balance - #{minBalance} where id = #{id}")
    void deductBalanceById(@Param("id") Integer id, @Param("minBalance") Integer minBalance);


    @Select("select * from address where user_id = #{id}")
    List<AddressPO> selectAddressByUserId(Long id);
}
